package org.agile4j.patterns.prototype.order;

/**
 * 处理订单的业务对象
 * 
 * @author user
 *
 */
public class OrderBusiness {

	/**
	 * 创建订单方法
	 * 
	 * @param order
	 *            订单的接口对象
	 */
	public void saveOrder(OrderApi order) {
		while (order.getOrderProductNum() > 1000) {
			OrderApi newOrder = null ;
			if (order instanceof EnterpriseOrder) {
				EnterpriseOrder p1 = (EnterpriseOrder)order;
				newOrder = (EnterpriseOrder) p1.clone() ;
			}
			if (order instanceof PersonalOrder) {
				PersonalOrder p1 = (PersonalOrder)order;
				newOrder = (PersonalOrder) p1.clone() ;
			}
//			if (order instanceof EnterpriseOrder) {
//				// 创建相应的新的订单对象
//				EnterpriseOrder p1 = new EnterpriseOrder();
//				EnterpriseOrder p2 = (EnterpriseOrder) order;
//				p1.setEnterpriseName(p2.getEnterpriseName());
//				p1.setProductId(p2.getProductId());
//				p1.setOrderProductNum(1000);
//				newOrder = p1;
//			}
//			if (order instanceof PersonalOrder) {
//				// 创建相应的新的订单对象
//				PersonalOrder p1 = new PersonalOrder();
//				PersonalOrder p2 = (PersonalOrder) order;
//				p1.setCustomerName(p2.getCustomerName());
//				p1.setProductId(p2.getProductId());
//				p1.setOrderProductNum(1000);
//				newOrder = p1;
//			}
			newOrder.setOrderProductNum(1000);
			System.out.println("newOrder:" + newOrder);
			order.setOrderProductNum(order.getOrderProductNum() - 1000);
		}
		System.out.println("order:" + order);
	}
}
